package com.fenghongzhang.module_main.glide.glide

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator
import com.bumptech.glide.module.AppGlideModule

/**
 *@author Wcj
 *@description
 *@date 2022/6/20 20:52
 */
@GlideModule
class GlideModule : AppGlideModule() {
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        val memorySizeCalculator = MemorySizeCalculator.Builder(context)
            .setMemoryCacheScreens(2.0f)
            .build()
        builder.setMemoryCache(LruResourceCache(memorySizeCalculator.memoryCacheSize.toLong()))
        //图片缓存路径修改,方便设置中清理图片缓存
        builder.setDiskCache(DiskLruCacheFactory(context.externalCacheDir?.path, "glide-cache", 1024 * 1024 * 20))
    }
}